package com.tiantianfresh.admin.controller;


import com.tiantianfresh.admin.service.CategorygroupingService;
import com.tiantianfresh.model.pojo.Categorygrouping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/categorygrouping")
public class CategorygroupingController {
    @Autowired
    private CategorygroupingService categorygroupingService;

    //查询categorygrouping
    @RequestMapping("/allCategorygrouping")
    public String list(Model model){
        List<Categorygrouping> list=categorygroupingService.selectAll();
        model.addAttribute("list",list);
        return "allCategorygrouping";
    }

    //跳转到添加categorygrouping页面
    @RequestMapping("/toadd")
    public String add(){
        return "add";
    }

    //添加categorygrouping
    @RequestMapping("/add")
    public String add(Categorygrouping categorygrouping){
       categorygroupingService.addCategorygrouping(categorygrouping);
        return "redirect:/categorygrouping/allCategorygrouping";
    }

    //删除categorygrouping
    @RequestMapping("/del/{id}")
    public String del(@PathVariable int id){
        categorygroupingService.deleteCategorygroupingById(id);
        return "redirect:/categorygrouping/allCategorygrouping";
    }

    //跳转到修改书籍页面
    @RequestMapping("/toupdate/{id}")
    public String update(@PathVariable int id,Model model){
        Categorygrouping categorygrouping = categorygroupingService.queryCategorygroupingById(id);
        model.addAttribute("Categorygrouping",categorygrouping);
        return "update";
    }

    //保存修改信息
    @RequestMapping("/update")
    public String update(Categorygrouping categorygrouping){
        categorygroupingService.updateCategorygrouping(categorygrouping);
        return "redirect:/categorygrouping/allCategorygrouping";
    }
}
